<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script>
    window.onload=function (){
      let oBtn=document.getElementById('btn1');
      let oSvg=document.createElementNS('http://www.w3.org/2000/svg', 'svg');
      oSvg.setAttribute('width', 800);
      oSvg.setAttribute('height', 600);

      document.body.appendChild(oSvg);

      oBtn.onclick=function (){
        //let oL=document.createElement('line');
        let oL=document.createElementNS('http://www.w3.org/2000/svg', 'line');

        //alert(oL);
        //alert(oSvg.children[0]);

        oL.setAttribute('x1', 100);
        oL.setAttribute('y1', 100);
        oL.setAttribute('x2', 400);
        oL.setAttribute('y2', 300);

        oL.style.stroke='red';

        oSvg.appendChild(oL);
      };
    };
    </script>
  </head>
  <body>
    <input type="button" id="btn1" name="" value="按钮"><br>

  </body>
</html>
